package com.atguigu.staservice.schedule;

import com.atguigu.staservice.service.StatisticsDailyService;
import com.atguigu.staservice.util.DateUtil;
import org.apache.velocity.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.servlet.ServletOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author 34633
 */
@Component
public class ScheduledTask {

    @Autowired
    private StatisticsDailyService statisticsDailyService;

    /**
     * 在每天凌晨1点,把前一天的数据进行查询添加，自动执行方法,把数据查询进行添加
     */
    @Scheduled(cron = "0 0 1 * * ? ")
    public void task1(){
        Date date = DateUtil.addDays(new Date(), -1);
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String dateString = formatter.format(date);
        statisticsDailyService.registerCount(dateString);

    }


}
